/*
 * Copyright (c) 2018.
 * http://www.ulabcare.com
 */

package com.mt.roll.upms.controller;

import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.params.EnabledParam;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.upms.params.SysOrgParam;
import com.mt.roll.upms.params.SysOrgQueryParam;
import com.mt.roll.upms.service.OrgService;
import com.mt.roll.upms.vo.SysOrgVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 平台组织控制器
 *
 * @author jiff
 * @date 2018/11/8
 * @since 1.0
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_UPMS +"org")
@Slf4j
@Api(value = "平台组织管理", tags = "平台组织管理接口", hidden = false)
public class OrgController extends BaseController {
    @Autowired
    private OrgService orgService;

    @PostMapping(value = "get")
    @ApiOperation(value = "获取组织")
    private R<SysOrgVo> get(@Validated @RequestBody IdParam idParam) {
        return orgService.get(idParam);
    }

    @PostMapping(value = "list")
    @ApiOperation(value = "获取组织列表")
    private R<List<SysOrgVo>> list(@Validated({Default.class}) @RequestBody SysOrgQueryParam sysOrgQueryParam) {
        return orgService.list(sysOrgQueryParam);
    }

    @PostMapping(value = "page")
    @ApiOperation(value = "获取分页组织")
    private R<PageVo<SysOrgVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody SysOrgQueryParam sysOrgQueryParam) {
        return orgService.page(sysOrgQueryParam);
    }

    @PostMapping(value = "tree")
    @ApiOperation(value = "获取组织树列表")
    private R<List<SysOrgVo>> tree(@Validated({Default.class}) @RequestBody SysOrgQueryParam sysOrgQueryParam) {
        return orgService.tree(sysOrgQueryParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody SysOrgParam sysOrgParam) {
        return orgService.add(sysOrgParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody SysOrgParam sysOrgParam) {
        return orgService.update(sysOrgParam);
    }

    @PostMapping(value = "enabled")
    @ApiOperation(value = "启停组织")
    private R<IdVo> enabled(@Validated @RequestBody EnabledParam enabledParam) {
        return orgService.enabled(enabledParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除组织")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return orgService.delete(idParam);
    }
}
